/**
 * Created by Administrator on 2020/5/15.
 */
;
var helper = require("../../javascript/helper");
var db = require("../../javascript/mysql");
var mysql = new db.mysqlClient("accident");
function genProductInfo() {
    plan = {
        "planA": {
            "year": ["18-65"],
            "days": ["1d", "3d", "7d", "30d", "90d"],
            "people_count": ["1"],
            "accident_death": ["0", "150000"],
            "accident_medical": ["0", "10000"],
            "sudden_disease": ["0", "150000"],
            "sudden_medical": ["0", "15000"],
            "accident_hospital": ["0", "100/天"]
            // "match_type": ['["高尔夫","健身","舞蹈","棋牌","钓鱼","瑜伽","徒步","羽毛球","网球","乒乓球","跑步","射击","射箭","电竞"]']
        },
        "planB": {
            "year": ["18-65"],
            "days": ["1d", "3d", "7d", "30d", "90d"],
            "people_count": ["1"],
            "accident_death": ["0", "100000"],
            "accident_medical": ["0", "10000"],
            "sudden_disease": ["0", "100000"],
            "sudden_medical": ["0", "10000"],
            "accident_hospital": ["0", "50/天"]
            // "match_type": ['["足球","登山","赛车",橄榄球","搏击",跆"拳道","滑雪","攀岩","滑冰","轮滑","骑行","游泳","露营"]']
        }

    };
    // var Sql = 'INSERT INTO `accident`(`year`,`days`,`people_count`,`accident_death`,`accident_medical`,`sudden_disease`,`sudden_medical`,`accident_hospital`,`match_type`)VALUES("{year}","{days}","{people_count}","{accident_death}","{accident_medical}","{sudden_disease}","{sudden_medical}","{accident_hospital}","{match_type}")';
    for (key in plan) {
        data = helper.product([plan[key]["year"], plan[key]["days"], plan[key]["people_count"], plan[key]["accident_death"], plan[key]["accident_medical"], plan[key]["sudden_disease"], plan[key]["sudden_medical"], plan[key]["accident_hospital"]]);
        for (i = 0; i < data.length; i++) {
            dt = ( helper.formatProductInfo(data[i], plan[key]) );
            if (dt["accident_death"] == "150000") {
                dt["match_type"] = ["高尔夫", "健身", "舞蹈", "棋牌", "钓鱼", "瑜伽", "徒步", "羽毛球", "网球", "乒乓球", "跑步", "射击", "射箭", "电竞"];
                price = calcPremium(dt);
                df = {
                    "name": '"赛出真我"综合意外险',
                    "company": "易安保险",
                    "price": (price.toFixed(2)).toString()
                };
                rs = Object.assign(df, dt);
                Sql = 'INSERT INTO `accident`(`name`,`company`,`price`,`year`,`days`,`people_count`,`accident_death`,`accident_medical`,`sudden_disease`,`sudden_medical`,`accident_hospital`,`match_type`)VALUES("赛出真我-综合意外险","易安保险","' + rs["price"] + '","18-65","' + rs["days"] + '","1","' + rs["accident_death"] + '","' + rs["accident_medical"] + '","' + rs["sudden_disease"] + '","' + rs["sudden_medical"] + '","' + rs["accident_hospital"] + '",' + "'" + JSON.stringify(rs["match_type"]) + "'" + ')';
                mysql.db.query(Sql, function (err, result) {

                    if (!err) {
                        console.log(Sql);
                    }

                })

            } else {
                dt["match_type"] = ["足球", "登山", "赛车", "橄榄球", "搏击", "跆拳道", "滑雪", "攀岩", "滑冰", "轮滑", "骑行", "游泳", "露营"]
                price = calcPremium(dt);
                df = {
                    "name": '"赛出真我"综合意外险',
                    "company": "易安保险",
                    "price": (price.toFixed(2)).toString()
                };
                rs = Object.assign(df, dt);
                Sql = 'INSERT INTO `accident`(`name`,`company`,`price`,`year`,`days`,`people_count`,`accident_death`,`accident_medical`,`sudden_disease`,`sudden_medical`,`accident_hospital`,`match_type`)VALUES("赛出真我-综合意外险","易安保险","' + rs["price"] + '","18-65","' + rs["days"] + '","1","' + rs["accident_death"] + '","' + rs["accident_medical"] + '","' + rs["sudden_disease"] + '","' + rs["sudden_medical"] + '","' + rs["accident_hospital"] + '",' + "'" + JSON.stringify(rs["match_type"]) + "'" + ')';

                mysql.db.query(Sql, function (err, result) {
                    if (!err) {
                        console.log(Sql);
                    }

                })

            }

        }
    }


}
//计算保费
function calcPremium(dt) {

    referers = {
        "1d": {
            "pase": 5,
            "accident_death": 1.5,
            "sudden_disease": 0.6,
            "sudden_medical": 3,
            "accident_hospital": 0.3
        },
        "3d": {
            "pase": 7.5,
            "accident_death": 2,
            "sudden_disease": 0.8,
            "sudden_medical": 3.9,
            "accident_hospital": 0.6

        },
        "7d": {
            "pase": 9.9,
            "accident_death": 3,
            "sudden_disease": 1,
            "sudden_medical": 4.9,
            "accident_hospital": 0.8

        },
        "30d": {
            "pase": 20.5,
            "accident_death": 4.5,
            "sudden_disease": 1.5,
            "sudden_medical": 9.5,
            "accident_hospital": 1

        },
        "90d": {
            "pase": 33.8,
            "accident_death": 7.5,
            "sudden_disease": 2.5,
            "sudden_medical": 13.5,
            "accident_hospital": 1.5

        }
    };

    refs = referers[dt["days"]];

    for (k in refs) {
        var price = refs["pase"];
        if (dt["accident_death"] != "0") {
            price += refs["accident_death"];


        } else {


        }
        if (dt["sudden_disease"] != "0") {
            price += refs["sudden_disease"]


        } else {

        }
        if (dt["sudden_medical"] != "0") {
            price += ( refs["sudden_medical"]);

        } else {


        }
        if (dt["accident_hospital"] != "0") {
            price += (refs["accident_hospital"]);
        }
        return price;

    }

}
genProductInfo();
mysql.close();

